package io.cici.cc.mybatis.lite.reflection.invoker;

import io.cici.cc.mybatis.lite.util.SecurityManagerUtil;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


public class MethodInvoker implements Invoker {


    private final Method method;

    public MethodInvoker(Method method) {
        this.method = method;

    }

    @Override
    public Object invoke(Object target, Object[] args) throws IllegalAccessException, InvocationTargetException {
        try {
            return method.invoke(target, args);
        } catch (IllegalAccessException e) {
            if (SecurityManagerUtil.memberAccessibleControl()) {
                method.setAccessible(true);
                return method.invoke(target, args);
            }
            throw e;
        }
    }

}
